package com.example.vo;

import java.util.Objects;

public class Animal {

    String name;
    double age;
    public Animal()
    {
        System.out.println("====Animal无参构造====");
    }
    public Animal(String name,double age)
    {
        this.age = age;
        this.name = name;
        System.out.println("====Animal有参构造====");
    }
    public void feed() {
        System.out.println("====Animal类无参喂狗====");
    }
    public void sayHello()
    {
        System.out.println("Animal" +
                "姓名" + this.name + "年龄" + this.age);
    }

    public void fly()
    {
        System.out.println("====Animal类fly====");
    }

    public void beat()
    {
        System.out.println("====Animal类beat====");
    }

    public void eat()
    {
        System.out.println("====Animal类eat====");
    }

    public void breath()
    {
        System.out.println("====Animal类breath====");
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }


    @Override
    public boolean equals(Object obj) {
        if (this == obj)//是否引用相同对象
        {//this == obj是用来判断两个对象是否引用相同的内存地址
            return true;
        }
        //是否为空
        //obj类是否与Animal类不同
        if (obj == null || getClass() != obj.getClass()) return false;
        Animal animal = (Animal) obj;
        return Double.compare(animal.age, age) == 0 &&
                Objects.equals(name, animal.name);

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getAge() {
        return age;
    }

    public void setAge(double age) {
        this.age = age;
    }
}
